//Desktop是JDK1.6的新特性，可以用其中的browse方法调用默认的浏览器来打开网页
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.URI;
import java.io.*;

public class Browse extends JFrame {
	private Container container;

	private Desktop desktop;

	private JLabel label;

	public Browse() {
		super("Browse测试");
		desktop = Desktop.getDesktop(); //Desktop类没有构造方法，只能用静态方法getDesktop返回当前浏览器上下文的 Desktop 实例

		label = new JLabel();
		label.setText("<html><A   href='http://www.google.cn'>谷歌</A></html>");//让字体以超文本的方式显示

		//为label注册鼠标监听器，若单击则打开网页
		label.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				try {
					desktop.browse(new URI("www.google.cn"));
				} catch (Exception e) {
				}
			}
		});
		container = getContentPane();
		container.setLayout(new FlowLayout());
		container.add(label);

		setVisible(true);
		pack();
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//使窗口屏幕居中
		Dimension frameSize, screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		frameSize = getSize();
		setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
	}

	public static void main(String args[]) {
		Browse browse = new Browse();
	}
}